import request from '@/utils/request';
import type { HttpResult } from '@/api';
import type { AddSysMenu, EditSysMenu, SysMenu } from './model';

// 新增
export const add = async (data: AddSysMenu): Promise<HttpResult<SysMenu>> => {
  const res = await request.post<HttpResult<SysMenu>>(
    '/system/sysMenu/add',
    data,
  );
  return res.data;
};

// 删除
export const del = async (id: string): Promise<HttpResult<string>> => {
  const res = await request.post<HttpResult<string>>(
    '/system/sysMenu/delete?id=' + id,
  );
  return res.data;
};

// 修改
export const edit = async (data: EditSysMenu): Promise<HttpResult<SysMenu>> => {
  const res = await request.post<HttpResult<SysMenu>>(
    '/system/sysMenu/edit',
    data,
  );
  return res.data;
};

// 查询某个
export const query = async (id: string): Promise<HttpResult<SysMenu>> => {
  const res = await request.post<HttpResult<SysMenu>>(
    '/system/sysMenu/query?id=' + id
  );
  return res.data;
};

// 查询列表
export const queryList = async (): Promise<HttpResult<SysMenu[]>> => {
  const res = await request.post<HttpResult<SysMenu[]>>(
    '/system/sysMenu/queryList', {}
  );
  return res.data;
};

// 查询树结构菜单
export const queryAllTree = async (): Promise<HttpResult<SysMenu[]>> => {
  const res = await request.post<HttpResult<SysMenu[]>>(
    '/system/sysMenu/allToTree', {}
  );
  return res.data;
};

